package tw.com.msig.xml;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

public class Dom4j03App {

	public static void main(String[] args) {

		URL url;
		try {
			url = new File("C:\\temp\\sample01.xml").toURI().toURL();
			SAXReader reader = new SAXReader();
			Document document = reader.read(url);

			List<Node> list = document.selectNodes("//policy/insureds/insured");

			for (Node node : list) {
				Element insured = (Element) node;
				System.out.println(insured.element("idNo").getText());
			}

		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (DocumentException e) {
			e.printStackTrace();
		}

	}

}
